package org.dromara.visitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.dromara.common.core.domain.R;
import org.dromara.visitor.domain.dto.RuleAddReq;
import org.dromara.visitor.domain.dto.RuleQueryReq;
import org.dromara.visitor.domain.dto.RuleResp;
import org.dromara.visitor.service.RuleService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 访问规则
 */
@RestController
@RequestMapping("/rule")
public class RuleController {
    @Resource
    private RuleService ruleService;

    /**
     * 规则新增
     * @param req
     * @return
     */
    @PostMapping("/add")
    public R addRule(@RequestBody RuleAddReq req){
        ruleService.addRule(req);
        return R.ok();
    }

    /**
     * 规则修改
     * @param req
     * @return
     */
    @PutMapping("/edit")
    public R editRule(@RequestBody RuleAddReq req){
        ruleService.editRule(req);
        return R.ok();
    }

    /**
     * 规则详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public R<RuleAddReq> detail(@RequestParam("id") Long id){
        RuleAddReq ruleAddReq = ruleService.detail(id);
        return R.ok(ruleAddReq);
    }

    /**
     * 规则列表
     * @param req
     * @return
     */
    @PostMapping("/list")
    public R<Page<RuleResp>> queryRuleList(@RequestBody RuleQueryReq req){
        Page<RuleResp> page = ruleService.queryRuleList(req);
        return R.ok(page);
    }
}
